using System;
using FireStarter.Base;
using FireStarterModeller.BO;
using Habanero.Base.Exceptions;
using NUnit.Framework;

namespace FireStarterModeller.Test.BO
{
    /// <summary>
    /// Provides a place to write custom tests for UIControlType objects.
    /// This file is only written once and can be changed.  The Def file
    /// attached to this as a dependent is rewritten with each regeneration
    /// and contains the standard tests for UIControlType.
    /// Regenerate this test project whenever there have been changes to the
    /// business objects.
    /// If tests are failing due to a unique setup in your application,
    /// you can either override the Create methods in TestUtils, or you
    /// can add the test to the ignore list below and reimplement it here.
    /// </summary>
    public partial class TestUIControlType
    {
        [TestFixtureSetUp]
        public void SetupTestFixture()
        {
            //------------------------------------------------------------
            // Use this list to ignore generated tests that are failing
            // due to a unique condition in your application.
            // Remember to reimplement the test here.
            //------------------------------------------------------------
            //_ignoreList.Add("TestMethodName", "Reason for ignoring it");
            base.SetupFixture();
        }

        [Test]
        public void Test_ToString()
        {
            //---------------Set up test pack-------------------
            UIControlType uiControlType = TestUtilsUIControlType.CreateUnsavedValidUIControlType();
            //---------------Assert Precondition----------------
            Assert.IsNotNull(uiControlType.Solution);
            TestUtilsShared.AssertStringNotEmpty(uiControlType.AssemblyName, "uiControlType.AssemblyName");
            TestUtilsShared.AssertStringNotEmpty(uiControlType.TypeName, "uiControlType.TypeName");
            //---------------Execute Test ----------------------
            string actualToString = uiControlType.ToString();
            //---------------Test Result -----------------------
            Assert.AreEqual
                (uiControlType.Solution + " - " + uiControlType.AssemblyName + "." + uiControlType.TypeName,
                 actualToString);
        }

        [Test]
        public void Test_ToString_SolutionNull()
        {
            //---------------Set up test pack-------------------
            UIControlType uiControlType = TestUtilsUIControlType.CreateUnsavedValidUIControlType();
            uiControlType.Solution = null;
            //---------------Assert Precondition----------------
            Assert.IsNull(uiControlType.Solution);
            TestUtilsShared.AssertStringNotEmpty(uiControlType.AssemblyName, "uiControlType.AssemblyName");
            //---------------Execute Test ----------------------
            string actualToString = uiControlType.ToString();
            //---------------Test Result -----------------------
            Assert.AreEqual(" - " + uiControlType.AssemblyName + "." + uiControlType.TypeName, actualToString);
        }

        [Test]
        public void Test_ToString_SolutionNull_AssemblyNameNull()
        {
            //---------------Set up test pack-------------------
            UIControlType uiControlType = TestUtilsUIControlType.CreateUnsavedValidUIControlType();
            uiControlType.AssemblyName = null;
            uiControlType.Solution = null;
            //---------------Assert Precondition----------------
            Assert.IsNull(uiControlType.Solution);
            TestUtilsShared.AssertStringEmpty(uiControlType.AssemblyName, "uiControlType.AssemblyName");
            //---------------Execute Test ----------------------
            string actualToString = uiControlType.ToString();
            //---------------Test Result -----------------------
            Assert.AreEqual(" - ." + uiControlType.TypeName, actualToString);
        }

        [Test]
        public void Test_ToString_SolutionNull_AssemblyNameNull_TypeNameNull()
        {
            //---------------Set up test pack-------------------
            UIControlType uiControlType = TestUtilsUIControlType.CreateUnsavedValidUIControlType();
            uiControlType.AssemblyName = null;
            uiControlType.Solution = null;
            uiControlType.TypeName = null;
            //---------------Assert Precondition----------------
            Assert.IsNull(uiControlType.Solution);
            TestUtilsShared.AssertStringEmpty(uiControlType.AssemblyName, "uiControlType.AssemblyName");
            TestUtilsShared.AssertStringEmpty(uiControlType.TypeName, "uiControlType.TypeName");
            //---------------Execute Test ----------------------
            string actualToString = uiControlType.ToString();
            //---------------Test Result -----------------------
            Assert.AreEqual(uiControlType.UIControlTypeID.ToString(), actualToString);
        }

        [Test]
        public void Test_ToString_SolutionNull_AssemblyNameNull_UIControlTypeIDNull()
        {
            //---------------Set up test pack-------------------
            UIControlType uiControlType = TestUtilsUIControlType.CreateUnsavedValidUIControlType();
            uiControlType.Solution = null;
            uiControlType.AssemblyName = null;
            uiControlType.TypeName = null;
            uiControlType.UIControlTypeID = null;
            //---------------Assert Precondition----------------
            Assert.IsNull(uiControlType.Solution);
            Assert.IsNull(uiControlType.AssemblyName);
            Assert.IsNull(uiControlType.UIControlTypeID);
            //---------------Execute Test ----------------------
            string actualToString = uiControlType.ToString();
            //---------------Test Result -----------------------
            Assert.AreEqual("-unnamed UIControlType-", actualToString);
        }
        [Test]
        public void Test_GetParent()
        {
            //---------------Set up test pack-------------------
            DMSolution dmSolution = new DMSolution();
            UIControlType uiControlType = new UIControlType();
            dmSolution.UIControlTypes.Add(uiControlType);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IModelElement parent = ((IModelElement)uiControlType).Parent;
            //---------------Test Result -----------------------
            Assert.AreSame(dmSolution, parent);
        }

        [Test]
        public void Test_SetParentExceptionThrown()
        {
            //---------------Set up test pack-------------------
            IModelElement prop = new UIControlType();

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            Exception exceptionThrown = null;
            try
            {
                prop.Parent = new DMSolution();
            }
            catch (Exception ex)
            {
                exceptionThrown = ex;
            }
            //---------------Test Result -----------------------
            Assert.IsNotNull(exceptionThrown);
            Assert.IsInstanceOf(typeof(HabaneroDeveloperException), exceptionThrown);
            StringAssert.Contains
                ("Set the parent of the UIControlType by setting the related Solution object", exceptionThrown.Message);
        }
    }
}